package com.gitee.zycra.future.job.service;

import com.gitee.zycra.future.job.common.bo.PageQuery;
import com.gitee.zycra.future.job.common.model.JobScheduleLog;
import com.gitee.zycra.future.job.common.param.PageQueryRunningParam;
import com.gitee.zycra.future.job.common.vo.JobRunningVO;
import com.gitee.zycra.future.job.manager.JobScheduleLogManager;
import com.gitee.zycra.jdbc.model.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zycra
 */
@Service
public class JobScheduleLogService {

    @Autowired
    private JobScheduleLogManager jobScheduleLogManager;

    /**
     * 根据任务调度ID查询
     *
     * @param pageQuery 查询参数
     * @return 查询到的数据
     */
    public PageResult<JobRunningVO> selectJobScheduleLog(PageQuery<PageQueryRunningParam> pageQuery) {
        PageResult<JobScheduleLog> result = jobScheduleLogManager.selectJobScheduleLog(pageQuery);
        List<JobScheduleLog> data = result.getData();
        List<JobRunningVO> voList = new ArrayList<>();
        for (JobScheduleLog jobScheduleLog : data) {
            voList.add(JobRunningVO.buildJobRunningVO(jobScheduleLog));
        }
        return new PageResult<>(result.getPage(), result.getTotal(), voList);
    }
}
